<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <meta name="author" content="PG-Strom Development Team">
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Index Support - PG-Strom Manual</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
  <link href="//fonts.googleapis.com/earlyaccess/notosansjp.css" rel="stylesheet">
  <link href="//fonts.googleapis.com/css?family=Open+Sans:600,800" rel="stylesheet">
  <link href="../custom.css" rel="stylesheet">
  
  <script>
    // Current page data
    var mkdocs_page_name = "Index Support";
    var mkdocs_page_input_path = "brin.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> PG-Strom Manual</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
  </form>

  [<a href="../ja" style="color: #cccccc">Japanese</a> | <strong>English</strong>]

</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <a class="" href="..">Home</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../install/">Install</a>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Tutorial</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../operations/">Basic Operations</a>
                </li>
                <li class="">
                    
    <a class="" href="../sys_admin/">System Administration</a>
                </li>
                <li class=" current">
                    
    <a class="current" href="./">Index Support</a>
    <ul class="subnav">
            
    <li class="toctree-l3"><a href="#overview">Overview</a></li>
    

    <li class="toctree-l3"><a href="#configuration">Configuration</a></li>
    

    <li class="toctree-l3"><a href="#operations">Operations</a></li>
    

    </ul>
                </li>
                <li class="">
                    
    <a class="" href="../partition/">Partitioning</a>
                </li>
                <li class="">
                    
    <a class="" href="../troubles/">Trouble Shooting</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Advanced Features</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../ssd2gpu/">SSD2GPU Direct SQL</a>
                </li>
                <li class="">
                    
    <a class="" href="../arrow_fdw/">Arrow_fdw</a>
                </li>
                <li class="">
                    
    <a class="" href="../gstore_fdw/">Gstore_fdw</a>
                </li>
                <li class="">
                    
    <a class="" href="../plcuda/">PL/CUDA</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">References</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../ref_types/">Data Types</a>
                </li>
                <li class="">
                    
    <a class="" href="../ref_devfuncs/">Functions and Operators</a>
                </li>
                <li class="">
                    
    <a class="" href="../ref_sqlfuncs/">SQL Objects</a>
                </li>
                <li class="">
                    
    <a class="" href="../ref_params/">GUC Parameters</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../release_note/">Release Note</a>
	    </li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">PG-Strom Manual</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
        
          <li>Tutorial &raquo;</li>
        
      
    
    <li>Index Support</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1>Index Support</h1>

<h1 id="overview">Overview</h1>
<p>PostgreSQL supports several index strategies. The default is B-tree that can rapidly fetch records with a particular value. Elsewhere, it also supports Hash, BRIN, GiST, GIN and others that have own characteristics for each.
PG-Strom supports only BRIN-index right now.</p>
<p>BRIN-index works efficiently on the dataset we can expect physically neighbor records have similar key values, like timestamp values of time-series data.
It allows to skip blocks-range if any records in the range obviously don't match to the scan qualifiers, then, also enables to reduce the amount of I/O due to full table scan.</p>
<p>PG-Strom also utilizes the feature of BRIN-index, to skip obviously unnecessary blocks from the ones to be loaded to GPU.</p>
<p><img alt="BRIN-index Ovewview" src="../img/brin-index-overview.png" /></p>
<h1 id="configuration">Configuration</h1>
<p>No special configurations are needed to use BRIN-index.</p>
<p>PG-Strom automatically applies BRIN-index based scan if BRIN-index is configured on the referenced columns and scan qualifiers are suitable to the index.</p>
<p>Also see the <a href="https://www.postgresql.org/docs/current/static/brin.html">PostgreSQL Documentation</a> for the BRIN-index feature.</p>
<p>By the GUC parameters below, PG-Strom enables/disables usage of BRIN-index. It usually don't need to change from the default configuration, except for debugging or trouble shooting.</p>
<table>
<thead>
<tr>
<th align="left">Parameter</th>
<th align="center">Type</th>
<th align="center">Default</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>pg_strom.enable_brin</code></td>
<td align="center"><code>bool</code></td>
<td align="center"><code>on</code></td>
<td align="left">enables/disables usage of BRIN-index</td>
</tr>
</tbody>
</table>
<h1 id="operations">Operations</h1>
<p>By <code>EXPLAIN</code>, we can check whether BRIN-index is in use.</p>
<pre><code>postgres=# EXPLAIN ANALYZE
           SELECT * FROM dt
            WHERE ymd BETWEEN '2018-01-01' AND '2018-12-31'
              AND cat LIKE '%aaa%';
                                   QUERY PLAN
--------------------------------------------------------------------------------
 Custom Scan (GpuScan) on dt  (cost=94810.93..176275.00 rows=169992 width=44)
                              (actual time=1777.819..1901.537 rows=175277 loops=1)
   GPU Filter: ((ymd &gt;= '2018-01-01'::date) AND (ymd &lt;= '2018-12-31'::date) AND (cat ~~ '%aaa%'::text))
   Rows Removed by GPU Filter: 4385491
   BRIN cond: ((ymd &gt;= '2018-01-01'::date) AND (ymd &lt;= '2018-12-31'::date))
   BRIN skipped: 424704
 Planning time: 0.529 ms
 Execution time: 2323.063 ms
(7 rows)
</code></pre>

<p>In the example above, BRIN-index is configured on the <code>ymd</code> column. <code>BRIN cond</code> shows the qualifier of BRIN-index for concentration. <code>BRIN skipped</code> shows the number of skipped blocks actually.</p>
<p>In this case, 424704 blocks are skipped, then, it filters out 4385491 rows in the loaded blocks by the scan qualifiers.</p>
<p>GpuJoin and GpuPreAgg often pulls up its underlying table scan and runs the scan by itself, to reduce inefficient data transfer. In this case, it also uses the BRIN-index to concentrate the scan.</p>
<p>The example below shows a usage of BRIN-index in a query which includes GROUP BY.</p>
<pre><code>postgres=# EXPLAIN ANALYZE
           SELECT cat,count(*)
             FROM dt WHERE ymd BETWEEN '2018-01-01' AND '2018-12-31'
         GROUP BY cat;
                                   QUERY PLAN
--------------------------------------------------------------------------------
 GroupAggregate  (cost=6149.78..6151.86 rows=26 width=12)
                 (actual time=427.482..427.499 rows=26 loops=1)
   Group Key: cat
   -&gt;  Sort  (cost=6149.78..6150.24 rows=182 width=12)
             (actual time=427.465..427.467 rows=26 loops=1)
         Sort Key: cat
         Sort Method: quicksort  Memory: 26kB
         -&gt;  Custom Scan (GpuPreAgg) on dt  (cost=6140.68..6142.95 rows=182 width=12)
                                            (actual time=427.331..427.339 rows=26 loops=1)
               Reduction: Local
               Outer Scan: dt  (cost=4000.00..4011.99 rows=4541187 width=4)
                               (actual time=78.573..415.961 rows=4560768 loops=1)
               Outer Scan Filter: ((ymd &gt;= '2018-01-01'::date) AND (ymd &lt;= '2018-12-31'::date))
               Rows Removed by Outer Scan Filter: 15564
               BRIN cond: ((ymd &gt;= '2018-01-01'::date) AND (ymd &lt;= '2018-12-31'::date))
               BRIN skipped: 424704
 Planning time: 30.992 ms
 Execution time: 818.994 ms
(14 rows)
</code></pre>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../partition/" class="btn btn-neutral float-right" title="Partitioning">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../sys_admin/" class="btn btn-neutral" title="System Administration"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../sys_admin/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../partition/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>

</body>
</html>
